import {LayerType, UIConfig} from "db://oops-framework/core/gui/layer/LayerManager";
import {oops} from "db://oops-framework/core/Oops";

// 界面唯一标识（方便服务器通过编号数据触发界面打开）
export enum UIID {
    // 资源加载界面
    loading = 1,
    // 请求错误
    errorRequest,
    login,
    // 资源加载
    netinstable,
    // 大厅界面
    dating,
    // 进入公共房(消耗 金豆)
    selectRubyDesk,
    // 创建麻将房
    createMjDesk,
    // 房间号
    deskNoKeyboard,
    // 带取消的弹窗
    dialogConfirm,
    // 不带取消的弹窗
    dialogNotify,
}

export const UIConfigData: { [key: number]: UIConfig} = {
    [UIID.loading]: {
        layer: LayerType.UI,
        prefab: "gui/loading/loading"
    },
    [UIID.errorRequest]: {
        layer: LayerType.PopUp,
        prefab: "common/prefab/notify",
    },
    [UIID.deskNoKeyboard]: {
        // 要允许错误弹窗提示，必须得 popup 层
        layer: LayerType.PopUp,
        prefab: "common/prefab/deskNoKeyboard",
    },
    [UIID.login]: {
        layer: LayerType.UI,
        prefab: "gui/login/login"
    },
    [UIID.netinstable]: {
        layer: LayerType.PopUp,
        prefab: "common/prefab/netinstable",
    },
    [UIID.dating]: {
        layer: LayerType.UI,
        prefab: "gui/dating/dating"
    },
    [UIID.selectRubyDesk]: {
        layer: LayerType.UI,
        prefab: "gui/selectRubyDesk/panel",
    },
    [UIID.createMjDesk]: {
        layer: LayerType.UI,
        prefab: "majiang/desk",
    },
    [UIID.dialogConfirm]: {
        layer: LayerType.Dialog,
        prefab: "common/prefab/dialogConfirm",
    },
    [UIID.dialogNotify]: {
        layer: LayerType.Dialog,
        prefab: "common/prefab/dialogNotify",
    },
}

// 打开弹窗
export const openDialogConfirm = (title: string, content: string, okCallback: Function, cancelCallback?: Function) => {
    if (!cancelCallback) {
        // 什么也不做
        cancelCallback = () => {}
    }
    oops.gui.open(UIID.dialogConfirm, {
        title,
        content,
        okWord: "确定",
        okFunc: okCallback,
        cancelWord: "取消",
        cancelFunc: cancelCallback,
        needCancel: true
    })
}
// 打开弹窗提示
export const openDialogNotify = (title: string, content: string, okCallback: Function) => {
    oops.gui.open(UIID.dialogNotify, {
        title,
        content,
        okWord: "确定",
        okFunc: okCallback,
        needCancel: false
    })
}